<?php
/**
 * @author Laurent SITTLER <lolo.sittler@gmail.com>
 * @author Alexandre GOMEZ <gomez.alexandre02@gmail.com>
 * @version 0.1
 */
/**
 *  View Manage Users (Admin)
 */
?>
<h3>Gérer les utilisateurs</h3>

<form action="<?php echo $GLOBALS['conf']['interface']['url']; ?>index/duser" method="post">
    <!-- Utilisateurs stockés en base de données -->
    <table id="listUser" class="tableContent">
        <tr>
            <th>
                &nbsp;
            </th>
            <th>
                Utilisateur
            </th>
            <th>
                Admin interface
            </th>
            <th>
                Status
            </th>
        </tr>

        <?php
        require_once 'Model/User_Model.php';
        require_once 'Library/User.php';
        $req = new User_Model();
        $listUser = $req->GetAllUsers();
        $lineU = 0;
        foreach ($listUser as $oUser) {
            if ($lineU % 2)
                echo '<tr class="style">';
            else
                echo '<tr>';
            echo '<td>';
            if ($oUser->GetId() == 1 || $oUser->GetId() == 2 || $oUser->GetId() == Session::Get(Constants::$SESSION_cuser))
                echo '<input type="checkbox" name="chk-' . $oUser->GetId() . '" disabled />';
            else
                echo '<input type="checkbox" name="chk-' . $oUser->GetId() . '" />';
            echo '</td>';
            echo '<td>';
            echo $oUser->GetLogin();
            echo '</td>';
            echo '<td style="text-align: center;">';
            if ($oUser->GetAdmin() == 1)
                echo '<span class="isValide">&nbsp;</span>';
            else
                echo '-';
            echo '</td>';
            echo '<td style="text-align: center;">';
            if ($oUser->GetStatus() == 1)
                echo '<span class="isValide">&nbsp;</span>';
            else
                echo '<span class="isInvalide">&nbsp;</span>';
            echo '</td>';
            echo '</tr>';
            $lineU++;
        }
        ?>
    </table>
    <br />
    <fieldset>
        <div class="legend"><span class="dUser">&nbsp;</span>Effacer les utilisateurs sélectionnés</div>
        (Effacer tous les utilisateurs.)<br />
        <input type="hidden" name="current-tab" value="<?php echo $j; ?>" />
        <input type="submit" value="Executer" />
    </fieldset>
</form>
<br />

<form action="<?php echo $GLOBALS['conf']['interface']['url']; ?>index/nuser" method="post">
    <fieldset>
        <div class="legend"><span class="aUser">&nbsp;</span>Ajouter un utilisateur</div>
        <table>
            <tr>
                <td>
                    <label for="ipt-login">Login</label>
                </td>
                <td>
                    <input type="text" id="ipt-login" name="login" />
                </td>
            </tr>
            <tr>
                <td>
                    <label for="ipt-firstName">Prénom</label>
                </td>
                <td><input type="text" id="ipt-firstName" name="firstName" />
                </td>
            </tr>
            <tr>
                <td>
                    <label for="ipt-lastName">Nom</label>
                </td>
                <td>
                    <input type="text" id="ipt-lastName" name="LastName" />
                </td>
            </tr>
            <tr>
                <td>
                    <label for="ipt-pwd">Mot de passe</label>
                </td>
                <td>
                    <input type="password" id="ipt-pwd" name="password" />
                </td>
            </tr>
            <tr>
                <td>
                    <label for="ipt-vpwd">Répéter le mot de passe</label>
                </td>
                <td>
                    <input type="password" id="ipt-vpwd" name="vpassword" />
                </td>
            </tr>
            <tr>
                <td>
                    <label for="chk-disable">Désactiver compte</label>
                </td>
                <td>
                    <input type="checkbox" id="chk-disable" name="status"  />
                </td>
            </tr>
            <tr>
                <td>
                    <label for="chk-admin">Admin de l'interface</label>
                </td>
                <td>
                    <input type="checkbox" id="chk-admin" name="admin" />
                </td>
            </tr>
        </table>
        <input type="hidden" name="current-tab" value="<?php echo $j; ?>" />
        <input type="submit" value="Executer" />
    </fieldset>
</form>

<div class="ui-widget">
    <div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
        <p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
            Liste des utilisateurs enregistrés dans la base de référence.</p>
    </div>
</div>